{include file="header/index" /}
<style>
    #dc{
        padding: 20px;
    }
    .dcinner{
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
    .dcbtn{
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-top: 15%;
    }
    .dcbtn button{
        margin-bottom: 10%;
    }
    .btn_search {
        background-color: #1273a3;
        color: #FFFFFF;
        border: none;
        padding: 0 20px;
        border-radius: 5px;
        margin: 0 10px;
        font-size: 16px;
        height: 32px;
        line-height: 32px;
    }
    .note{
        color: red;
    }
    .layui-upload-file{
        display: none;
    }
    .import_but input{
        display: none;
    }
    .btn_search:hover{
        background-color: #0088cc;
    }
</style>
<div class="container whitebg">
    <div id="dc">
        <div class="dcinner">
            <div class="choosedate mr5">
                <input class="form-control" type="text" placeholder="开始时间(安装时间)" id="datetimeStart1" value=""  class="form_datetime">
            </div>
            <div class="choosedate mr20">
                <input class="form-control" type="text" placeholder="结束时间(安装时间)"  id="datetimeEnd1"  value=""  class="form_datetime">
            </div>
        </div>
        <div class="dcbtn">
            <div class="import_but" style="display: flex;">
                <button type="button" onclick="export1()" class="btn_search">导出</button>
                <button type="button" onclick="export3()" class="btn_search">导出(含关系)</button>
                <button type="button" class="layui-btn btn_search" style="background-color: #009688" id="test1">
                    <i class="layui-icon">&#xe67c;</i>导入合同
                </button>
                <a href="http://{$_SERVER['HTTP_HOST']}/customer/new/润泉导入合同模版.xlsx" class="layui-btn btn_search">下载导入模版</a>
                <!--<button type="button" class="btn_search">下载导入模版</button>-->
            </div>
            <span class="note">注：当导出数据量过多时，可能造成导出失败。若导出含关系合同，可能关系不存在，可以在业绩系统中根据工单查看关系.
                <br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                导入时出现在<strong>“请求接口异常”</strong>，请联系开发人员.
            </span>
        </div>
        <div class="dcinner">

        </div>
    </div>

</div>

</body>

</html>
<script src="__JS__/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '{:url("Contractinfo/import")}' //上传接口
            ,accept: 'file'
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                var index = layer.load(1, {
                    shade: [0.3,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(res){
                //上传完毕回调
                console.log(res);
                layer.closeAll();
                if (res.code > 0){
                    top.layer.msg(res.msg, {icon: 1,time: 5000});
                    return false;
                }
                top.layer.msg(res.msg, {icon: 2,time: 5000});
                return false;
            }
            ,error: function(){
                //请求异常回调
                // layer.closeAll();
            }
        });
    });


    $("#datetimeStart1").datetimepicker({
        language: 'cn',
        format: "yyyy-mm-dd",
        autoclose: true,
        minView: "month",
        maxView: "decade",
        todayBtn: true,
        pickerPosition: "bottom-left"
    }).on("click", function(ev) {
        console.log(222);
        $("#datetimeStart1").datetimepicker("setEndDate", $("#datetimeEnd1").val());
    });



    $("#datetimeEnd1").datetimepicker({
        language: 'cn',
        format: "yyyy-mm-dd",
        autoclose: true,
        minView: "month",
        maxView: "decade",
        todayBtn: true,
        pickerPosition: "bottom-left"
    }).on("click", function(ev) {
        $("#datetimeEnd1").datetimepicker("setStartDate", $("#datetimeStart1").val());
    });

    function export1() {
        var start_time = $("#datetimeStart1").val();
        var end_time = $("#datetimeEnd1").val();

        if (start_time == ''){
            top.layer.msg('请选择开始时间', {icon: 2});
            return false;
        }
        if (end_time == ''){
            top.layer.msg('请选择结束时间', {icon: 2});
            return false;
        }

        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });

        setTimeout(function () {
            layer.close(index);
        },3000);
        top.layer.msg('正在下载，请耐心等候！', {icon: 7});
        window.location.href = "{:url('admin/Contractinfo/Excel')}?start_time=" + start_time +'&end_time='+end_time;
    }

    function export3() {
        var start_time = $("#datetimeStart1").val();
        var end_time = $("#datetimeEnd1").val();

        if (start_time == ''){
            top.layer.msg('请选择开始时间', {icon: 2});
            return false;
        }
        if (end_time == ''){
            top.layer.msg('请选择结束时间', {icon: 2});
            return false;
        }

        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });

        setTimeout(function () {
            layer.close(index);
        },3000);
        top.layer.msg('正在下载，请耐心等候！', {icon: 7});
        window.location.href = "{:url('admin/Contractinfo/exportExcelRelation')}?start_time=" + start_time +'&end_time='+end_time;
    }
</script>